home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / grid.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  6KB  |  217 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "const.h"
  13. #include "func.h"
  14. #include "paintop.h"
  15.  
  16. static int    cur_grid = -1;
  17. extern int    CANVAS_WIDTH, CANVAS_HEIGHT;
  18.  
  19. #ifndef    X11
  20. PIXRECT    h_grid_pr=0, v_grid1_pr=0, v_grid2_pr=0;
  21.  
  22. #ifndef AMIGA
  23. init_grid()
  24. {
  25.     int    x, y;
  26.     extern int pots[];
  27.  
  28.     h_grid_pr = mem_create(CANVAS_WIDTH, 1, 1);
  29.     v_grid1_pr = mem_create(1, CANVAS_HEIGHT, 1);
  30.     v_grid2_pr = mem_create(1, CANVAS_HEIGHT, 1);
  31.     for (x = 4; x < CANVAS_WIDTH; x +=5)
  32. #ifdef AMIGA
  33.         ((USHORT *)v_grid1_pr)[x/16]|=pots[15-(x&15)];
  34. #else
  35.         pr_put(v_grid1_pr, x, 0, 1);
  36. #endif
  37.     for (x = 0, y = 4; y <= CANVAS_HEIGHT; x++, y +=5)
  38.         if (x == 3)
  39.         x = -1;
  40.         else
  41. #ifdef AMIGA
  42.         ((USHORT *)v_grid1_pr)[y]=32768;
  43. #else
  44.         pr_put(v_grid1_pr, 0, y, 1);
  45. #endif
  46.     for (x = 0, y = 4; y <= CANVAS_HEIGHT; x++, y +=5)
  47.         if (x == 7)
  48.         x = -1;
  49.         else
  50. #ifdef AMIGA
  51.         ((USHORT *)v_grid1_pr)[y]=32768;
  52. #else
  53.         pr_put(v_grid2_pr, 0, y, 1);
  54. #endif
  55.     }
  56. #endif
  57.  
  58. setup_grid(grid)
  59. int    grid;
  60. {
  61.     if (cur_grid == grid) {
  62.         cur_grid = -1;
  63.         }
  64.     else {
  65.         if (grid == F_GRID1)
  66.         put_msg("Half centimeter GRID");
  67.         else
  68.         put_msg("One centimeter GRID");
  69.         if (cur_grid != -1) {
  70.         draw_grid(cur_grid);
  71.         }
  72.         cur_grid = grid;
  73.         }
  74.     draw_grid(grid);
  75.     }
  76.  
  77.  
  78. draw_grid(grid)
  79. int    grid;
  80. {
  81. #ifdef AMIGA
  82.     extern struct Window *AnotherWindow;
  83. #endif /* AMIGA */
  84.  
  85.     int         x, y, resolution;
  86.     PIXRECT        v_grid_pr;
  87.     extern struct RastPort * RastPort;
  88.  
  89.     if (grid == F_GRID1) {
  90.         v_grid_pr = v_grid1_pr;
  91.         resolution = PIX_PER_CM / 2;
  92.         }
  93.     else {
  94.         v_grid_pr = v_grid2_pr;
  95.         resolution = PIX_PER_CM;
  96.         }
  97.  
  98.     /*  vertical grid  */
  99. #ifdef AMIGA
  100.     SetDrPt(RastPort,0x4444);
  101.     SetDrMd(RastPort,COMPLEMENT);
  102. /*    for (x = 100+resolution - 1; x <= CANVAS_WIDTH; x += resolution)*/
  103.     for (x = resolution - 1; x <= AnotherWindow -> Width; x += resolution)
  104. /*        {Move(RastPort,x,12);*/
  105.         {Move(RastPort,x,0);
  106.          Draw(RastPort,x,AnotherWindow -> Height);}
  107. #else
  108.     for (x = resolution - 1; x <= CANVAS_WIDTH; x += resolution)
  109.         pw_write(canvas_pixwin, x, 0, 1, CANVAS_HEIGHT, INV_PAINT, 
  110.             v_grid_pr, 0, 0);
  111. #endif
  112.     /*  horizontal grid  */
  113. #ifdef AMIGA
  114. /*    for (y = 12+resolution - 1; y <= CANVAS_HEIGHT; y += resolution)*/
  115.     for (y = resolution - 1; y <= AnotherWindow -> Height; y += resolution)
  116. /*     {Move(RastPort,100,y);*/
  117.      {Move(RastPort,0,y);
  118.       Draw(RastPort,AnotherWindow -> Width,y);}
  119.     SetDrMd(RastPort,JAM1);
  120.     SetDrPt(RastPort,0xffff);
  121. #else
  122.     for (y = resolution - 1; y <= CANVAS_HEIGHT; y += resolution)
  123.         pw_write(canvas_pixwin, 0, y, CANVAS_WIDTH, 1, INV_PAINT, 
  124.             h_grid_pr, 0, 0);
  125. #endif
  126.     }
  127.  
  128. redisplay_grid()
  129. {
  130.     if (cur_grid == -1) return;
  131.     draw_grid(cur_grid);
  132.     }
  133.  
  134. #else
  135.  
  136. #define null_width 32
  137. #define null_height 32
  138. static char null_bits[null_width * null_height / 8] = { 0 };
  139.  
  140. #define quarter_width 20
  141. #define quarter_height 20
  142. static char quarter_bits[] = {
  143.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  144.    0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  145.    0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  146.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
  147.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x42, 0x08};
  148.  
  149. #define half_width 40
  150. #define half_height 40
  151. static char half_bits[] = {
  152.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  153.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  154.    0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  155.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  156.    0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  157.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  158.    0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  159.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  160.    0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  161.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  162.    0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  163.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  164.    0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  165.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  166.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  167.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  168.    0x00, 0x00, 0x00, 0x10, 0x42, 0x08, 0x21, 0x84};
  169.  
  170. static Pixmap    null_pm, quarter_pm, half_pm;
  171.  
  172. init_grid()
  173. {
  174.     long    bg, fg;
  175.     Arg    tmp_arg[3];
  176.  
  177.     XtSetArg(tmp_arg[0], XtNbackground, &bg);
  178.     XtSetArg(tmp_arg[1], XtNforeground, &fg);
  179.     XtGetValues(canvas_sw, tmp_arg, 2);
  180.     
  181.     null_pm = XCreatePixmapFromBitmapData(tool_d, canvas_pixwin,
  182.         null_bits, null_width, null_height,
  183.         fg, bg,    DefaultDepthOfScreen(tool_s));
  184.     quarter_pm = XCreatePixmapFromBitmapData(tool_d, canvas_pixwin,
  185.         quarter_bits, quarter_width, quarter_height,
  186.         fg, bg,    DefaultDepthOfScreen(tool_s));
  187.     half_pm = XCreatePixmapFromBitmapData(tool_d, canvas_pixwin,
  188.         half_bits, half_width, half_height,
  189.         fg, bg,    DefaultDepthOfScreen(tool_s));
  190. }
  191.  
  192. setup_grid(grid)
  193.     int        grid;
  194. {
  195.     static Arg    grid_args[] =
  196.     {
  197.         { XtNbackgroundPixmap, (XtArgVal)NULL },
  198.     };
  199.  
  200.     if (grid == cur_grid)
  201.     {
  202.         grid_args[0].value = (XtArgVal)null_pm;
  203.         grid = -1;
  204.     }
  205.     if (grid == F_GRID1)
  206.         grid_args[0].value = (XtArgVal)quarter_pm;
  207.     else if (grid == F_GRID2)
  208.         grid_args[0].value = (XtArgVal)half_pm;
  209.     cur_grid = grid;
  210.     XtSetValues(canvas_sw, grid_args, XtNumber(grid_args));
  211. }
  212.  
  213. redisplay_grid()
  214. {
  215. }
  216. #endif    X11
  217.